{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# iflearner server Configure and start"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 虚拟环境\n",
    "可以通过conda、pyenv等虚拟工具创建iflearner的虚拟运行环境，然后激活。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1. Conda\n",
    "1.需要安装conda环境。 [安装](https://docs.conda.io/projects/conda/en/stable/user-guide/install/index.html)\n",
    "\n",
    "2.我们将通过conda创建一个虚拟环境并激活它\n",
    "```shell\n",
    "$ conda create -n iflearner python==3.9 ipykernel\n",
    "$ conda activate iflearner\n",
    "```\n",
    "\n",
    "3.将虚拟环境写入jupyter notebook内核\n",
    "命令：python -m ipykernel install --user --name 虚拟环境名称 --display-name 虚拟环境名称\n",
    "- 第一个虚拟环境名称表示创建的虚拟环境名称\n",
    "- 第二个虚拟环境名称表示您希望它出现在 jupyter notebook 的内核选项中\n",
    "\n",
    "   例如： $ python -m ipykernel install --user --name iflearner --display-name \"iflearner\"\n",
    "\n",
    "4.切换内核\n",
    "可以在jupyterlab的内核菜单栏中选择更改内核按钮，选择我们创建的虚拟环境"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.安装iflearner库及相关依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: http://172.31.164.23:8083/simple, http://pypi.douban.com/simple\n",
      "Collecting iflearner\n",
      "  Using cached iflearner-0.2.0-py3-none-any.whl\n",
      "Installing collected packages: iflearner\n",
      "Successfully installed iflearner-0.2.0\n"
     ]
    }
   ],
   "source": [
    "!pip install iflearner --ignore-installed --index-url http://172.31.164.23:8083/simple --extra-index-url http://pypi.douban.com/simple \\\n",
    "--trusted-host 172.31.164.23 --trusted-host pypi.douban.com"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.启动服务器端"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'iflearner.business'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m        Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-17-086562cbb75b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0margparse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0miflearner\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbusiness\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhomo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maggregate_server\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mAggregateServer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0miflearner\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommunication\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhomo\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmessage_type\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'iflearner.business'"
     ]
    }
   ],
   "source": [
    "\n",
    "from iflearner.business.homo.aggregate_server import main\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "iflearner",
   "language": "python",
   "name": "iflearner"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
